﻿toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    var divImage = $id("divImage_" + fsid);
    //var btn = $id("btn_" + fsid);
    //var btnEdit = $id("btnEdit_" + fsid);
    //var load = $id("load_" + fsid);
        
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    divImage.style.display = display;
    //btn.style.display = display;
    //btnEdit.style.display = display;
    //load.style.display = display;
}

Upload = function()
{
    //alert("save" + iCustID);
    var load = $id("load2");
    var btn = $id("btnUpload");
    //var btnCancel = $id("btnCancel");
    if(confirm("save changes?"))
    {
        // di sini kirim data perubahannya
        var input = getData();
        //alert(input);
//        if(input)
//        {
            btn.style.display = "none";
            //btnCancel.style.display = "none";
            load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
            cbkMRTG_c.PerformCallback("UPLOAD" + DELIMITER + input);
//        }
//        else
//        {
//            btn.style.display = "inline";
//            btnCancel.style.display = "inline";
//            load.innerHTML = "";
//        }
    }
}
Generate = function()
{
    var lovNetwork = $id("lov_MRTG.NETWORK");
    var network = lovNetwork.value;
    var type = $id("MRTG.TIME");
    var Start = $id("MRTG.STARTDATE");
    var End = $id("MRTG.ENDDATE");
    var load = $id("load1");
    var btn = $id("btnGenerate");
    //btn.style.display = "none";
    load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
    //var input = getData();
    //alert(network+startdate+enddate);
    
    cbkMRTG_c.PerformCallback("GENERATE" + DELIMITER + network + DELIMITER + Start.value + DELIMITER + End.value + DELIMITER + type.value);
}
cbkMRTG_c_CallbackComplete = function(e) 
{
    var selector = e.result.split(DELIMITER)[0];
    var div = $id("div_MRTG");
    var divImage = $id("divImage_MRTG");
    var load1 = $id("load1");
    var load2 = $id("load2");   
    if(selector == "GENERATE")
    {
        load1.style.display = "none";
        divImage.innerHTML = e.result.split(DELIMITER)[1];
    }
    if(selector == "UPLOAD")
    {
        load2.style.display = "none";
        divImage.innerHTML = "";
        div.innerHTML = e.result.split(DELIMITER)[1];
    }
}
getData = function()
{
    var inputs = $nm("txt");
    var output = "";
    var lovNetwork = $id("lov_MRTG.NETWORK");
    var lovhCompany = $id("lovh_MRTG.CUSTOMERID");
    var image = $id("MRTG.IMAGE");
    
    output += "MRTG.NETWORK" + NEWLINE + lovNetwork.value;
//    output += DELIMITER + "MRTG.IMAGE" + NEWLINE + image.src;
    output += DELIMITER + "MRTG.CUSTOMERID" + NEWLINE + lovhCompany.value + DELIMITER;
    
    for( var i=0; i < inputs.length; i++ )
    {
        if( i > 0 )
        {
            output += DELIMITER;
        }
        
        var item = inputs[i];
        var lov = $id("lov_" + item.id);
        
        if( lov == null )
        {
            output += item.id + NEWLINE + item.value;
        }
        else
        {
            var lovh = $id("lovh_" + item.id);
            output += lov.value + NEWLINE + lovh.value + NEWLINE + item.value;
                   
        }
    }
    output += DELIMITER + "MRTG.IMAGE" + NEWLINE + image.src;
    return output;
}

SelectCompany = function()
{
    var lovhCompany = $id("lovh_MRTG.CUSTOMERID");
    var lovpNetwork = $id("lovp_MRTG.NETWORK");
    var lovNetwork = $id("lov_MRTG.NETWORK");
    var lovhNetwork = $id("lovh_MRTG.NETWORK");
    
    if(lovpNetwork.value != lovhCompany.value )
    {    
        lovNetwork.value = "";
        lovhNetwork.value = "";
    }
    
    lovpNetwork.value = lovhCompany.value;
    //alert(lovpNetwork.value);
}
SelectTimeRange = function()
{
    var cmbTime = $id("MRTG.TIME");
    var divDate = $id("divDate");
    var txtStartDate = $id("MRTG.STARTDATE");
    var txtEndDate = $id("MRTG.ENDDATE");
    if(cmbTime.value=="CUSTOM")
    {
        divDate.style.display = "block";
    }
    else
    {
        divDate.style.display = "none";
    }    
}
SelectNetworkInfo = function()
{
    //do nothing
}
